#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    string ans1(vector<string>& strs){
        int length = strs.size();
        int i, j = 0;
        string out = "";
        int str_length = 9999;
        for(i = 0; i != length; i++){
            int temp = strs[i].size();
            str_length = min(str_length, temp);
        }
        while(true){
            int counts = 1;
            if(length == 1){
                return strs[0];
            }
            if(str_length == 0){
                return out;
            }
            for(i = 0; i != length-1; i++){
                if(strs[i][j] == strs[i+1][j]){
                    counts++;
                }
            }
            if(counts == length){
                out.push_back(strs[i][j]);
            }else{
                break;
            }
            j++;
            if(j >= str_length){
                break;
            }
        }
        return out;
    }
};

void test1(){
    Solution s;
    vector<string> strs = {"flower", "flow", "flight"};
    string ret = s.ans1(strs);
    cout << ret << endl;
}

void test2(){
    Solution s;
    vector<string> strs = {"dog","racecar","car"};
    string ret = s.ans1(strs);
    cout << ret << endl;
}

void test3(){
    Solution s;
    vector<string> strs = {"", ""};
    string ret = s.ans1(strs);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}